<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title">导入数据</h4>
</div>
<form id="defaultForm" method="post" class="form-horizontal" action="/project/indexManage/statusImport_Data">
    <input name="id"  style="display: none">
    <div class="modal-body">

        <div class="form-group">
            <label class="col-lg-3 control-label">文件</label>
            <div class="col-lg-5">
                <input type="text" class="form-control" id = "filename" name="filename" accept="text/plain"/>
            </div>

            <div class="col-lg-2">

                <button type="button" id="uploadExcel"class="btn btn-success fileinput-button" data-btn-type="selectIcon">打开</button>

            </div>
            <div class="col-lg-2">
                <a href="/project/indexManage/status_exportTemplate"><p style="font-size:16px">模板</p></a>
            </div>
        </div>
    </div>


</form>

<script>

    $("#uploadExcel").upload({
        action:"/project/indexManage/statusImport_Data", //表单提交的地址
        name:"myFile",
        onComplete:function (data) {
            if(data == "0"){
                alert("Excel导入成功")
            }else{
                alert("Excel导入失败")
            }
            $("#modal").modal("hide");
            $("#dataTable").bootstrapTable('refresh', {url: '/project/indexManage/status_data'});
        },
        onSelect: function() {
            //当选择了文件后，关闭自动提交
            this.autoSubmit=false;
            //校验上传的文件名是否满足后缀为.xls或.xlsx
            var regex =/^.*\.(?:xls|xlsx)$/;
            //校验
            if(regex.test($("[name = '"+this.name()+"']").val())){
                //通过校验
                this.submit();
            }else{
                //未通过
                alert("文件格式不正确，必须以.xls或.xlsx结尾")
            }
        }
    });



</script>